<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <style>
        .sapan-bottom{
            color: red;
            font-size: 20px; /* 调整为你想要的字体大小 */
        }
    </style>
    <th:block th:include="include :: header('任务管理器列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>商家名称：</label>
                                <input type="text" name="mercName"/>
                            </li>
                            <li>
                                <label>店铺名称：</label>
                                <input type="text" name="storeName"/>
                            </li>
                            <li>
                                <label>产品链接：</label>
                                <input type="text" name="productLink"/>
                            </li>
                            <li>
                                <label>客服名称：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>收货姓名：</label>
                                <input type="text" name="personName"/>
                            </li>
                            <li>
                                <label>收货电话：</label>
                                <input type="text" name="personTele"/>
                            </li>
                            <li>
                                <label>任务备注：</label>
                                <input type="text" name="remark"/>
                            </li>
                            <li>
                                是否出评：<select name="isEvaluate" th:with="type=${@dict.getType('is_evaluate')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li>
                                是否结算：<select name="isSettleAccounts" th:with="type=${@dict.getType('is_settle_accounts')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li class="select-time">
                                <label>创建时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn btn-w-m btn-success" onclick="openPerson()"   shiro:hasPermission="require:task">
                    <i class="fa fa-edit"></i> 获取任务
                </a>
                <a class="btn btn btn-w-m btn-success multiple disabled" onclick="receiveTask()" shiro:hasPermission="recovery:task">
                    <i class="fa fa-edit"></i> 回收任务
                </a>
                <a class="btn btn btn-w-m btn-success multiple disabled" onclick="copyTask()" shiro:hasPermission="copy:task">
                    <i class="fa fa-edit"></i> 复制任务
                </a>
                <a class="btn btn btn-w-m btn-success multiple disabled" onclick="batchSettle()" shiro:hasPermission="batch:settle">
                    <i class="fa fa-edit"></i> 批量结算
                </a>
                <a class="btn btn btn-w-m btn-success multiple disabled" onclick="batchEvaluate(0)" shiro:hasPermission="batch:select:evaluate">
                    <i class="fa fa-edit"></i> 批量选择出评
                </a>
                <a class="btn btn btn-w-m btn-success multiple disabled" onclick="batchEvaluate(1)" shiro:hasPermission="batch:select:not:evaluate">
                    <i class="fa fa-edit"></i> 批量选择不出评
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:manage:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:manage:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:manage:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
                <span class="sapan-bottom">核实总数:</span>
                <span class="sapan-bottom" th:if="${totalCount != null}" th:text="${totalCount}"></span>
                <span  class="sapan-bottom">出评:</span>
                <span class="sapan-bottom" th:if="${totalEvaluate != null}" th:text="${totalEvaluate}"></span>
                <span  class="sapan-bottom">不出评:</span>
                <span class="sapan-bottom" th:if="${totalNotEvaluate != null}" th:text="${totalNotEvaluate}"></span>
                <span  class="sapan-bottom">出评率:</span>
                <span class="sapan-bottom" th:if="${evaluateRate != null}" th:text="${evaluateRate} + '%'"></span>
            </div>

        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:manage:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:manage:remove')}]];
        var isEvaluateDatas = [[${@dict.getType('is_evaluate')}]];
        var isSettleAccountsDatas = [[${@dict.getType('is_settle_accounts')}]];
        var isCopyDatas = [[${@dict.getType('is_copy_task')}]];
        var prefix = ctx + "system/manage";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                copyUrl: prefix + "/copyTask/{id}",
                pageSize:150,
                settleUrl: prefix + "/settleInit/{id}",
                removeUrl: prefix + "/remove",
                recoveryUrl: prefix + "/recovery",
                exportUrl: prefix + "/export",
                modalName: "任务管理器",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键id',
                    visible: false
                },
                {
                    field: 'mercName',
                    title: '商家名称'
                },
                {
                    field: 'storeName',
                    title: '店铺名称'
                },
                {
                    field: 'productLink',
                    title: '产品链接'
                },
                {
                    field: 'userName',
                    title: '客服名称'
                },
                {
                    field: 'remark',
                    title: '任务备注'
                },
                {
                    field: 'personName',
                    title: '收货姓名'
                },
                {
                    field: 'personTele',
                    title: '收货电话'
                },
                {
                    field: 'address',
                    title: '收货地址'
                },
                {
                    field: 'productAmount',
                    title: '单价(元)'
                },
                {
                    field: 'actualAmount',
                    title: '实付价(元)'
                },
                {
                    field: 'isEvaluate',
                    title: '是否出评',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isEvaluateDatas, value);
                    }
                },
                {
                    field: 'isSettleAccounts',
                    title: '是否结算',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isSettleAccountsDatas, value);
                    }
                },
                {
                    field: 'iscopy',
                    title: '是否复制',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(isCopyDatas, value);
                    }
                },
                {
                    field: 'personRemark',
                    title: '客服备注'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            return actions.join('');
                        }
                  }]
            };
            $.table.init(options);
        });

        /**
         * 获取任务
         */
        function openPerson() {
            $.modal.open("人员获取任务信息", prefix+"/personList",);
        }

        /**
         * 回收任务
         */
        function receiveTask(){
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要回收选中的" + rows.length + "条数据吗?", function () {
                var url = table.options.recoveryUrl;
                var data = {"ids": rows.join()};
                $.operate.submit(url, "post", "json", data);
            });
        };

        /**
         * 复制任务
         */
        function copyTask(){
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var _url = table.options.copyUrl.replace("{id}",rows.join());
            $.modal.open("复制任务", _url);
        };

        /**
         * 批量结算
         */
        function batchSettle() {
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var url = table.options.settleUrl.replace("{id}", rows.join());
            $.modal.open("任务结算", url);
        };

        /**
         * 批量出评
         */
        function batchEvaluate(type) {
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要处理选中的" + rows.length + "条数据吗?", function () {
                $.operate.get(prefix + "/batchEvaluate/"+rows.join()+"/"+type,function (result) {
                    if(result.code==0){
                        parent.$.modal.msgSuccess(result.msg);
                    }else{
                        parent.$.modal.msgError(result.msg);
                    }
                    $.table.refresh();
                });
            });

        }
    </script>
</body>
</html>